package com.atguigu.study.bootredis.config;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author jiangta
 * @version 1.0
 * @date 2020/12/2 4:21 下午
 */
@Configuration
public class ZookeeperConfig {

    @Value("${spring.zookeeper.host}")
    private String zookeeperHost;

    @Value("${spring.zookeeper.port}")
    private String zookeeperPort;


    /**
     * Guava is to Java what Curator is to Zookeeper
     *
     * @return
     */
    @Bean
    public CuratorFramework getCuratorFramework() {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeperHost + ":" + zookeeperPort, retryPolicy);
        return client;
    }
}
